import React from 'react';
import { ts2Formatter,renderState,renderEnable } from 'utils';
import { actions } from 'mirrorx';
{/*
可配置化种类：

1、表格头部字段 
    1、列表页表格头部字段集合 mainTableColumn
    2、编辑页表格头部字段集合 childTableColumn

2、编辑框的字段
    1、编辑页 直接显示在页面的编辑字段 FormField
    2、编辑页 需要点击表格的增行弹框编辑的字段 FormTableField
    3. 列表页查询区域  searchField

3.表头部的按钮  headerButtonSets

4.表行尾部按钮  columnButtonSets
*/}

//表头信息

//字段属性

//基本信息
const FormDataHeader = [
    {
        enname: "code",
        zhname: "单据号",
        edit: false,
        hidepage:{0:true},
        type: "FormControl",
    },
    {
        enname: "organizationId",
        codename: "organizationCode",
        showname: "organizationName",
        zhname: "所属组织",
        type: "RefComponent",
        edit:true,
        refname:"organization",
        required: true,
        cascadeChildTable:[{
            refKey: "refpk", 
            dtoKey: "organizationId",
            childType:"budgetAdjustDetails" 
        }],
    },
    {
        enname: "deptId",
        codename: "deptCode",
        showname: "deptName",
        zhname: "部门片区",
        type: "RefComponent",
        edit:false,
        refname:"departmentRef",
        required: true,
    },
    {
        enname: "adjustTypeId",
        codename: "adjustTypeCode",
        showname: "adjustTypeName",
        zhname: "调整类型",
        edit: true,
        type: "Select",
        code:"ADJUST_TYPE",
        required: true,
    },
    {
        enname: "adjustExplain",
        zhname: "调整说明",
        type: "FormControl",
        required: true,
        pattern: /^\S*$/,
        message: "不能有空格",
        edit: true,
    },
    {
        enname: "budgetPlanId",
        codename: "budgetPlanBillCode",
        showname: "budgetPlanPlanName",
        zhname: "预算方案",
        type: "RefComponent",
        edit:false,
        refname:"departmentRef",
        required: true,
    },
    {
        enname: "budgetItemId",
        codename: "budgetItemCode",
        showname: "budgetItemName",
        zhname: "预算项目",
        type: "RefComponent",
        edit:false,
        refname:"budgetItemRef",
        required: true,
    },
    {
        enname: "budgetUnitId",
        codename: "budgetUnitCode",
        showname: "budgetUnitName",
        zhname: "预算单元",
        edit: false,
        type: "RefComponent",
        refname:"budgetUnitRef",
        required: true,
    },
    {
        enname: "budgetPriority",
        zhname: "预算优先级",
        type: "FormControl",
        required: false,
        hidepage: { 0: true },
        edit: false,
    },
    {
        enname: "adjustAmount",
        zhname: "总调整金额",
        type: "FormControl",
        edit: false,
    },
    {
        codename: "state",
        zhname: "审批状态",
        hidepage:{0:true,3:true},
        edit: false,
        code:"BILL_STATUS",
        type: "Select",
        required: false,
    },
    {
        enname:"approveTime",
        zhname:"审核日期",
        required: false,
        hidepage:{0:true,1:false,2:false,3:true},
        type: "DatePicker",
        format:"YYYY-MM-DD",
        edit: false
    },
    {
        enname: "ext01",
        zhname: "创建人",
        type: "FormControl",
        required: false,
        hidepage: { 0:true,3:true },
        edit: true,
    },
    {
        enname: "creationTime",
        zhname: "创建日期",
        type: "DatePicker",
        required: false,
        format: "YYYY-MM-DD",
        hidepage: { 0:true,3:true },
        edit: true,
    },
    {
        enname: "ext02",
        zhname: "编辑人",
        type: "FormControl",
        required: false,
        hidepage: { 0:true,3:true },
        edit: true,
    },
    {
        enname: "modifiedTime",
        zhname: "编辑日期",
        type: "DatePicker",
        format: "YYYY-MM-DD",
        required: false,
        hidepage: { 0:true,3:true },
        edit: true,
    },
];

const columnbudgetAdjustDetails = [
    {
        title: "公司",
        dataIndex: "saleOrgName",
        key: "saleOrgId",
        detailwidth: 250,
        required:true,
        hidepage: { 0: true, 1: true, 2: true },
        filedProps: {
            title: "公司",
            refName: "organization",
            constparam:{
                "AUTH_refdim": "organization", 
                "AUTH_refcod": "BudgetAdjust",
            },
            aliasparam: [{
                paramkey: "EQ_id",
                alias: "organizationId",
            }],
            multiple:true,
            fieldName: "saleOrgName",
            reffields: { refpk: "saleOrgId", refcode: "saleOrgCode", refname: "saleOrgName" }
        },
    }, 
    {
        title: "部门",
        dataIndex: "departmentName",
        key: "departmentId",
        detailwidth: 250,
        required:true,
        hidepage: { 0: true, 1: true, 2: true },
        filedProps: {
            title: "部门",
            refName: "departmentRef",
            constparam:{
                "AUTH_refdim": "department", 
                "AUTH_refcod": "BudgetAdjust",
            },
            multiple:true,
            fieldName: "departmentName",
            reffields: { refpk: "departmentId", refcode: "departmentCode", refname: "departmentName" }
        },
    },
    {
        title: "渠道",
        dataIndex: "channelName",
        key: "channelId",
        detailwidth: 250,
        required:true,
        hidepage: { 0: true, 1: true, 2: true },
        filedProps: {
            title: "渠道",
            refName: "custchantype",
            multiple:true,
            fieldName: "channelName",
            reffields: { refpk: "channelId", refcode: "channelCode", refname: "channelName" }
        },
    },
    {
        title: "客户",
        dataIndex: "customerName",
        key: "customerId",
        detailwidth: 250,
        required:true,
        hidepage: { 0: true, 1: true, 2: true },
        filedProps: {
            title: "客户",
            refName: "terminalcustomerRef",
            constparam:{
                "AUTH_refdim": "customer", 
                "AUTH_refcod": "BudgetAdjust",
            },
            multiple:true,
            fieldName: "customerName",
            reffields: { refpk: "customerId", refcode: "customerCode", refname: "customerName" }
        },
    },
    {
        title: "门店",
        dataIndex: "terminalStoreName",
        key: "terminalStoreId",
        detailwidth: 250,
        required:true,
        hidepage: { 0: true, 1: true, 2: true },
        filedProps: {
            title: "门店",
            refName: "terminal",
            constparam:{
                "AUTH_refdim": "termianl", 
                "AUTH_refcod": "BudgetAdjust",
            },
            multiple:true,
            fieldName: "terminalStoreName",
            reffields: { refpk: "terminalStoreId", refcode: "terminalStoreCode", refname: "terminalStoreName" }
        },
    },
    {
        title: "预算期数",
        dataIndex: "budgetPeriodMonth",
        key: "budgetPeriodMonth",
        renderType: 'selectradio',
        required:true,
        detailwidth: 70,
        validate:false,
        hidepage: { 0: true, 1: true, 2: true },
        render: (text, record, index) => {
            if (text == 1) {
                return '1期';
            }else if(text == 2){
                return '2期';
            }else if(text == 3){
                return '3期';
            }else if(text == 4){
                return '4期';
            }else if(text == 5){
                return '5期';
            }else if(text == 6){
                return '6期';
            }else if(text == 7){
                return '7期';
            }else if(text == 8){
                return '8期';
            }else if(text == 9){
                return '9期';
            }else if(text == 10){
                return '10期';
            }else if(text == 11){
                return '11期';
            }else if(text == 12){
                return '12期';
            }
        },
        filedProps: {
            reffields: { refpk: "budgetPeriodMonth" },
            options: [
                {
                    name: '1期', code: 1
                },
                {
                    name: '2期', code: 2
                },
                {
                    name: '3期', code: 3
                },
                {
                    name: '4期', code: 4
                },
                {
                    name: '5期', code: 5
                },
                {
                    name: '6期', code: 6
                },
                {
                    name: '7期', code: 7
                },
                {
                    name: '8期', code: 8
                },
                {
                    name: '9期', code: 9
                },
                {
                    name: '10期', code: 10
                },
                {
                    name: '11期', code: 11
                },
                {
                    name: '12期', code: 12
                },
            ]
        }
    },
    {
        title: "预算期数",
        dataIndex: "budgetPeriodQuarter",
        key: "budgetPeriodQuarter",
        renderType: 'selectradio',
        required:true,
        detailwidth: 70,
        validate:false,
        hidepage: { 0: true, 1: true, 2: true },
        render: (text, record, index) => {
            if (text == 1) {
                return '1期';
            }else if(text == 2){
                return '2期';
            }else if(text == 3){
                return '3期';
            }else if(text == 4){
                return '4期';
            }
        },
        filedProps: {
            reffields: { refpk: "budgetPeriodQuarter" },
            options: [
                {
                    name: '1期', code: 1
                },
                {
                    name: '2期', code: 2
                },
                {
                    name: '3期', code: 3
                },
                {
                    name: '4期', code: 4
                }
            ]
        }
    },
    {
        title: "预算期数",
        dataIndex: "budgetPeriodHalfYear",
        key: "budgetPeriodHalfYear",
        renderType: 'selectradio',
        required:true,
        detailwidth: 70,
        validate:false,
        hidepage: { 0: true, 1: true, 2: true },
        render: (text, record, index) => {
            if (text == 1) {
                return '1期';
            }else if(text == 2){
                return '2期';
            }
        },
        filedProps: {
            reffields: { refpk: "budgetPeriodHalfYear" },
            options: [
                {
                    name: '1期', code: 1
                },
                {
                    name: '2期', code: 2
                }
            ]
        }
    },
    {
        title: "预算期数",
        dataIndex: "budgetPeriodYear",
        key: "budgetPeriodYear",
        renderType: 'selectradio',
        required:true,
        detailwidth: 70,
        validate:false,
        hidepage: { 0: true, 1: true, 2: true },
        render: (text, record, index) => {
            if (text == 1) {
                return '1期';
            }
        },
        filedProps: {
            reffields: { refpk: "budgetPeriodYear" },
            options: [
                {
                    name: '1期', code: 1
                },
            ]
        }
    },
    {
        dataIndex: "planSaleAmount",
        key: "planSaleAmount",
        title: "计划销售额-变动值",
        detailwidth: 100,
        required:true,
        edit: true,
        renderType: "inputnumber",
        hidepage: { 0: true, 1: true, 2: true },
    },
    {
        dataIndex: "planRetailAmount",
        key: "planRetailAmount",
        title: "计划零售额-变动值",
        detailwidth: 100,
        required:true,
        edit: true,
        renderType: "inputnumber",
        hidepage: { 0: true, 1: true, 2: true },
    },
    {
        dataIndex: "subtractAmount",
        key: "subtractAmount",
        title: "调出金额",
        detailwidth: 100,
        required:true,
        edit: true,
        renderType: "inputnumber",
        hidepage: { 0: true, 1: true, 2: true },
        filedProps: {
            min: 0,
        }
    },
    {
        dataIndex: "addAmount",
        key: "addAmount",
        title: "追加金额",
        detailwidth: 100,
        required:true,
        edit: true,
        renderType: "inputnumber",
        hidepage: { 0: true, 1: true, 2: true },
        filedProps: {
            min: 0
        }
    },
]

//表单字段
export const FormField = {
    "DataHeader": {
        "title": "基础信息",
        "Field": FormDataHeader
    },
}

//表格弹框表单字段
export const FormTableField = {
}

//渲染成字表表格的头
export const childTableColumn = {
    "budgetAdjustDetails": {
        "title": "活动方案明细",
        "type": "grid",
        "column": columnbudgetAdjustDetails
    },
}

//渲染成字表表格的头
export const mainTableColumn = [
    {
        title: "单据号",
        dataIndex: "code",
        width: 150,
        key: "billCode",
        render: (text, record) => {
            return <a style={{ "cursor": "pointer" }}
                onClick={() => {
                    actions.routing.push(
                        {
                            pathname: 'BudgetAdjust-edit',
                            search: `?search_id=${record.id}&btnPageFlag=2`,
                        }
                    );
                    // location.reload();
                }}
            >
                {text}
            </a >;
        }
    },
    {
        title: "所属组织",
        dataIndex: "organizationName",
        key: "organizationName",
    },
    {
        title: "部门片区",
        dataIndex: "deptName",
        key: "deptName",
    },
    {
        title: "调整类型",
        dataIndex: "adjustTypeName",
        key: "adjustTypeName",
    },
    {
        title: "调整说明",
        dataIndex: "adjustExplain",
        key: "adjustExplain",
    },
    {
        title: "审批状态",
        dataIndex: "state",
        key: "state",
        width: 70,
        render:(text, record, index)=> {
            return renderState(text);
        },
    },
    {
        title:"审核日期",
        dataIndex:"approveTime",
        key: "approveTime",
        width: 90,
        render:(text) => {
            return text && ts2Formatter(text);
        },
    },
    {
        title: "预算方案",
        width: 120,
        dataIndex: "budgetPlanName",
        key: "budgetPlanName",
    },
    {
        title: "预算项目",
        width: 120,
        dataIndex: "budgetItemName",
        key: "budgetItemName",
    },
    {
        title: "总调整金额",
        width: 120,
        dataIndex: "adjustAmount",
        key: "adjustAmount",
    },
    
    {
        title: "创建人",
        width: 120,
        dataIndex: "ext01",
        key: "ext01",
    },
    {
        title: "创建日期",
        dataIndex: "creationTime",
        key: "creationTime",
        width: 120,
        render: (text) => {
            return text && ts2Formatter(text)
        }
    },
    {
        title: "修改人",
        width: 120,
        dataIndex: "ext02",
        key: "ext02",
    },
    {
        title: "修改日期",
        dataIndex: "modifiedTime",
        key: "modifiedTime",
        width: 120,
        render: (text) => {
            return text && ts2Formatter(text)
        }
    },
]

export const searchField = [
    {
        enname: "creationTime",
        zhname: "制单日期",
        required: false,
        type: "RangePicker",
        rangeField: ["creationTime", "creationTime"],
        edit: true
    },
    {
        enname: "billCode",
        zhname: "单据号",
        required: false,
        type: "FormControl",
        searchType:"like",
        edit: true
    },
    {
        enname: "organization",
        zhname: "所属组织",
        required: false,
        refname:"organization",
        realRef:true,
        param:{
            "AUTH_refdim": "organization", 
            "AUTH_refcod": "ExpenseSummary"
        },
        type: "RefComponent",
        edit: true
    },
    {
        enname:"state",
        zhname:"审批状态",
        required: false,
        code:"BILL_STATUS",
        type: "Select",
        edit: true
    },
]

export const headerButtonSets = [
    // {
    //     event: "ButtonAdd",
    //     zhname: "新增",
    //     color: 'primary',
    //     authcode: "9901-05-02-01",
    // }
    // {
    //     event: "ButtonEnable",
    //     zhname: "启用",
    //     authcode: "BudgetAdjuststart",
    //     method: "post",
    //     batch:true,
    //     ContentType: 'application/x-www-form-urlencoded;charset=utf-8',
    //     url: 'occ-fee/fee/expense-summary/enable'
    // },
    // {
    //     event: "ButtonEnable",
    //     zhname: "停用",
    //     authcode: "BudgetAdjuststop",
    //     method: "post",
    //     batch:true,
    //     ContentType: 'application/x-www-form-urlencoded;charset=utf-8',
    //     url: 'occ-fee/fee/expense-summary/disenable'
    // }
]

export const columnButtonSets = {
    "delete": {
        event: "ButtonDel",
        zhname: "删除",
        batch: true,
        method: "post",
        ContentType: 'application/x-www-form-urlencoded;charset=utf-8',
        url: 'occ-fee/fee/budget-adjusts/deleteWithFriendly'
    },
    "edit": true,
    "detail": true
}

// export default {mainTableColumn,searchField,headerButtonSets,
//     columnButtonSets,childTableColumn,FormTableField,FormField}
export const SelectCode = ["BILL_STATUS","ADJUST_TYPE"]
